#!/usr/bin/env python
# -*- coding:utf-8 -*-

'''
    OSG第三方依赖库合并到单一目录
    历史:
        姚彧 2017-02-12 创建
'''

import os
import shutil

def copy_files_in_dir(source_dir, dest_dir):
    assert(os.path.isdir(source_dir)), source_dir
    if not os.path.isdir(dest_dir):
        os.makedirs(dest_dir)
    for item in os.listdir(source_dir):
        src_name = os.path.join(source_dir, item)
        dest_name = os.path.join(dest_dir, item)
        if os.path.isfile(src_name):
            print('  %s -> %s' % (src_name, dest_name))
            shutil.copy2(src_name, dest_name)
        elif os.path.isdir(src_name):
            copy_files_in_dir(src_name, dest_name)

    

if __name__ == '__main__':
    import os
    def get_filename(rootdir):
        rootdir = os.path.abspath(rootdir)
        def __call__(name):
            return os.path.join(rootdir, name)
        return __call__
    get_src_name = get_filename(r'F:\Develop\bin\x64')
    get_dst_name = lambda x: r'F:\Develop\bin\x64\usr'
    
    publish_list = ['curl-7.52.1', 
                    'freetype-2.7',
                    'giflib-5.1.4',
                    'glut',
                    'jpeg-9b',
                    'libpng-1.6.28',
                    'libssh2-1.8.0',
                    'minizip',
                    'OpenSSL-1.0.2',
                    'tiff-4.0.7',
                    'zlib-1.2.8',
                    'libiconv',  #1.15
                    ]
    for name in publish_list:
        src = get_src_name(name)
        dst = get_dst_name(name)
        print('%s -> %s' % (src, dst))
        if os.path.isfile(src):
            shutil.copy2(src, dst)
        elif os.path.isdir(src):    
            copy_files_in_dir(src, dst)
        else:
            print('  --> 错误文件: %s' % src)
    print('文件发布完成')